package com.gitee.qdbp.base.i18n;

import org.aspectj.lang.ProceedingJoinPoint;
import org.springframework.beans.factory.annotation.Autowired;
import com.gitee.qdbp.able.result.ResponseMessage;
import com.gitee.qdbp.tools.utils.VerifyTools;

/**
 * 结果返回码国际化的切面处理类
 *
 * @author zhaohuihua
 * @version 181107
 */
public class ResponseMessageI18nAspect {

    @Autowired
    private IResultCodeI18nResolver resultCodeI18nResolver;

    /** 切面处理 **/
    public Object doAround(ProceedingJoinPoint point) throws Throwable {
        try {
            Object returns = point.proceed();
            if (returns instanceof ResponseMessage) {
                ResponseMessage resp = (ResponseMessage) returns;
                String message = resultCodeI18nResolver.getResultCodeMessage(resp.getCode());
                if (VerifyTools.isNotBlank(message)) {
                    resp.setMessage(message);
                }
            }
            return returns;
        } catch (Throwable e) {
            throw e;
        }
    }
}
